package com.yt.order.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.yt.order.models.dto.DispatchRuleFilterDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.yt.order.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yt.order.mapper.EmpRatingStatsMapper;
import com.yt.order.models.service.IEmpRatingStatsService;
import com.yt.order.models.bo.EmpRatingStatsSaveBO;
import com.yt.order.models.dto.EmpRatingStatsDTO;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 员工星级表控制器
 *
 * @author zhou
 * @Date 2025-09-15 16:19:26
 */
@DubboService
public class EmpRatingStatsServiceImpl extends ServiceImpl<EmpRatingStatsMapper, EmpRatingStatsDTO> implements IEmpRatingStatsService{

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(EmpRatingStatsSaveBO saveBO) {
        EmpRatingStatsDTO dto = new EmpRatingStatsDTO();
        BeanUtils.copyProperties(saveBO,dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }

    @Override
    public List<Long> queryId(String operator, String val) {
        BigDecimal value=new BigDecimal(val);
        Wrapper<EmpRatingStatsDTO> wrapper = new EntityWrapper<EmpRatingStatsDTO>();
        //大于等于的查询条件
        if(operator==">="){
            wrapper.ge("total_rating",value);
        }
        //小于等于的查询条件
        if(operator=="<="){
            wrapper.le("total_rating",value);
        }
        //大于的查询条件
        if(operator==">"){
            wrapper.gt("total_rating",value);
        }
        //等于的查询条件
        if(operator=="="){
            wrapper.eq("total_rating",value);
        }
        //小于的查询条件
        if(operator=="<"){
            wrapper.lt("total_rating",value);
        }
        //返回形式为列表(员工id)形式
        return this.selectList(wrapper).stream()
                .map(EmpRatingStatsDTO::getEmpId)
                .collect(Collectors.toList());
    }

    @Override
    public List<Long> queryEmp() {
        return baseMapper.queryEmpId();
    }

    @Override
    public void updateStar(Long empId) {
        baseMapper.updateSta(empId);
    }
}
